/*
 *  AMacFileLocator.cpp
 *  libavid
 *
 *  Created by Peter on 24.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "AMacFileLocator.h"
#include "AStream.h"

A_IMPLEMENT_CLASS( '----', AFileLocator, AObject ); // Unknown PCID
A_IMPLEMENT_CLASS( 'FILE', AMacFileLocator, AFileLocator );

void AMacFileLocator::readFromStream( AStream& str, const AObjDoc& objd )
{
	UInt8 tagMarker, version;
	
	str.readPod( tagMarker );
	str.readPod( version );
	
	TR_ASSERT( tagMarker == 0x02 );
	TR_ASSERT( version == 2 );
	
	_pathName = str.readString();	
	
	// The following is a PClass extension that stores the POSIX path name. It 
	// is only present if _pathName isn't an empty string. Go figure.
	if( _pathName != "" )
	{
		// Minor version
		str.readPod( tagMarker );
		str.readPod( version );
	
		TR_ASSERT( tagMarker == 0x01 );
		TR_ASSERT( version == 1 );
	
		// Some PClass Ext marker the Avid engineers like
		str.readPod( tagMarker );
		TR_ASSERT( tagMarker == 76 );
	
		_posixPathName = str.readString();
	} 
	else
	{
		// At least initialize properly
		_posixPathName = "";
	}
	
	UInt8 endTagMark;
	str.readPod( endTagMark );
	TR_ASSERT( endTagMark == 0x03 );
}

void AMacFileLocator::dump( std::ostream& str ) const
{
	str << "AMacFileLocator {" << std::endl;
	str << "\t_pathName: " << _pathName << std::endl;
	str << "\t_posixPathName: " << _posixPathName << std::endl;
	str << "}" << std::endl;
}